package org.javagril.yuetong.controller.truck;

import org.javagril.yuetong.bean.RespBean;
import org.javagril.yuetong.bean.RespPageBean;
import org.javagril.yuetong.bean.Truck;
import org.javagril.yuetong.bean.TruckTeam;
import org.javagril.yuetong.service.TruckService;
import org.javagril.yuetong.service.TruckTeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author QingtungTree
 * @Datetime: 2019/12/24
 * @Description:org.javagril.yuetong.controller.truck
 * @Version:
 */
@RestController
@RequestMapping("/truck/team")
public class TruckTeamController {
    @Autowired
    TruckTeamService truckTeamService;
    @Autowired
    TruckService truckService;
    @GetMapping("/")
    public RespPageBean getAllTruckTeam(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
        return truckTeamService.getAllTruckTeam(page,size);
    }

    /* 通过 "@PathVariable" 获取id*/
    @GetMapping("/{id}")
    public List<Truck> getTruckTeamByTruckTeamId(@PathVariable Integer id){
        return truckTeamService.getTruckTeamByTruckTeamId(id);
    }

    /*所有车队车辆信息*/
    @GetMapping("/trucks")
    public List<Truck> getAllTrucks() {
        return (List<Truck>) truckService.getAllTrucksByPage(null, null).getData();
    }




    /*车队车辆添加*/
    @PostMapping("/")
    public RespBean addTruckTeam(@RequestBody TruckTeam truckTeam) {
        if (truckTeamService.addTruckTeam(truckTeam)) {
            return RespBean.ok("车队信息添加成功...o(*￣▽￣*)ブ");
        }
        return RespBean.error("车队信息添加失败...(￣、￣)");
    }

    /*车队修改操作*/
    @PutMapping("/")
    public RespBean updateTruckTeam(@RequestBody TruckTeam truckTeam) {
        if (truckTeamService.updateTruckTeam(truckTeam)) {
            return RespBean.ok("车队信息更新成功...o(*￣▽￣*)ブ");
        }
        return RespBean.error("车队信息更新失败...(￣、￣)");
    }

    /*删除车队操作*/
    @DeleteMapping("/{id}")
    public RespBean deleteTruckTeam(@PathVariable Integer id){
        if(truckTeamService.deleteTruckTeam(id) == 1){
            return RespBean.ok("车队信息删除成功...o(*￣▽￣*)ブ");
        }
        return RespBean.error("车队信息删除失败...(￣、￣)");
    }

}



